import { connect } from 'react-redux'
import { fetchPostsIfNeeded } from '../../state/actions'
import Test from '../Test/Test'

const mapStateToProps = (state = {
    count: 0,
    color: 'red',
    resData: 'no data yet',
}) => {
    return {
        count: state.count,
        color: state.color,
        resData: state.resData,
    }
}

const mapDispatchToProps = dispatch => {
    return {
        onGetClicked: fetchConf => {
            console.log('entered getClicked');
            dispatch(fetchPostsIfNeeded(fetchConf));
        },
        onPostClicked: fetchConf => {
            console.log('entered onPostClicked');
            dispatch(fetchPostsIfNeeded(fetchConf))
        },
        onGetProxyClicked: fetchConf => {
            console.log('entered onGetProxyClicked');
            dispatch(fetchPostsIfNeeded(fetchConf))
        },
    }
}

const TestState = connect(
    mapStateToProps,
    mapDispatchToProps
)(Test)

export default TestState